package org.infosys.system.controller;

import org.infosys.basic.utils.AjaxResult;
import org.infosys.basic.utils.PageList;
import org.infosys.system.domain.Dictionarydetail;
import org.infosys.system.query.DictionarydetailQuery;
import org.infosys.system.service.IDictionarydetialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dictionarydetail")
public class DictionarydetailController {

    @Autowired
    private IDictionarydetialService dictionarydetialService;

    /**
     * @Title: loadAll
     * @Description: 查询所有员工信息
     * @Author: hank
     * @Version: 1.0
     * @Date:  2022/6/26 12:38
     * @Parameters: []
     * @Return java.util.List<org.infosys.org.domain.Employee>
     */
    @GetMapping
    public List<Dictionarydetail> loadAll() {
        return dictionarydetialService.loadAll();
    }

    /**
     * @Title: loadById
     * @Description: 根据id查询员工
     * @Author: hank
     * @Version: 1.0
     * @Date:  2022/6/26 21:27
     * @Parameters: [id]
     * @Return org.infosys.org.domain.Employee
     */
    @GetMapping("/{id}")
    public Dictionarydetail loadById(@PathVariable("id") Long id) {
        return dictionarydetialService.loadById(id);
    }

    /**
     * @Title: remove
     * @Description: 根据Id删除员工
     * @Author: hank
     * @Version: 1.0
     * @Date:  2022/6/26 21:36
     * @Parameters: [id]
     * @Return org.infosys.basic.utils.AjaxResult
     */
    @DeleteMapping("/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        try {
            dictionarydetialService.remove(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg("系统繁忙，请稍后再试!").setSuccess(false);
        }
    }

    /**
     * @Title: addOrUpt
     * @Description: 修改和新增
     * @Author: hank
     * @Version: 1.0
     * @Date:  2022/6/26 22:20
     * @Parameters: [employee]
     * @Return org.infosys.basic.utils.AjaxResult
     */
    @PutMapping
    public AjaxResult addOrUpt(@RequestBody Dictionarydetail Dictionarydetail) {
        try {
            if (ObjectUtils.isEmpty(Dictionarydetail.getId())) {
                dictionarydetialService.save(Dictionarydetail);
            } else {
                dictionarydetialService.update(Dictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg("系统繁忙,请稍后再试!").setSuccess(false);
        }
    }

    /**
     * @Title: queryEmployee
     * @Description: 条件查询
     * @Author: hank
     * @Version: 1.0
     * @Date:  2022/6/26 23:02
     * @Parameters: [employeeQuery]
     * @Return org.infosys.basic.utils.PageList<org.infosys.org.domain.Employee>
     */
    @PostMapping
    public PageList<Dictionarydetail> queryEmployee(@RequestBody DictionarydetailQuery dictionarydetailQuery) {
        return dictionarydetialService.loadQuery(dictionarydetailQuery);
    }

    @PatchMapping
    public AjaxResult patchDel(@RequestBody Long[] ids) {
        try {
            dictionarydetialService.patchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMsg("系统繁忙，请稍后重试!").setSuccess(false);
        }
    }
}
